package com.andyou.rest.web;

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.Consumes;
import javax.ws.rs.FormParam;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.andyou.common.mapper.JsonMapper;
import com.andyou.common.persistence.Page;
import com.andyou.common.utils.StringUtils;
import com.andyou.common.ws.ReturnResult;
import com.andyou.rest.entity.AuthEnum;
import com.andyou.rest.entity.PerstateManageArea;
import com.andyou.rest.entity.ResponseBody;
import com.andyou.rest.service.DataService;
import com.andyou.rest.service.PerstateManageAreaService;


@Path("/data")
@Component
public class DataController {
	
	/**
	 * 日志对象
	 */
	protected Logger logger = LoggerFactory.getLogger(DataController.class);
	@Autowired
	private DataService dataService;
	
	@Autowired
	private PerstateManageAreaService perstateManageAreaService;
	
	
	
	/**
	 * 社区业态综合数据-集团业态收费面积
	 * 
	 * @param sso 
	 * 			验证信息
	 * @param pageSize
	 *            每页显示条数
	 * @param pageIndex
	 *            第几页
	 * @param where
	 *        查询条件
	 *  @param orderby
	 *        排序字段
	 * @return 集团业态收费面积查询列表（json）
	 * @author lgx Date:2016年5月5日；
	 */
	@POST
	@Path("/getPerstateManageAreaGroupList")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<ReturnResult> getPerstateManageAreaGroupList(@FormParam("sso") String sso,@FormParam("pageSize") int pageSize,@FormParam("pageIndex") int pageIndex,
			@FormParam("where") String where,@FormParam("orderby") String orderby) 
	{
		ResponseBody<ReturnResult> body = new ResponseBody<ReturnResult>();
		try
		{
			Map<String, Object> mapJsonSso  = (Map<String, Object>)JsonMapper.fromJsonString(sso,Map.class);
			if(mapJsonSso.get("token")!=null)
			{
				PerstateManageArea perstateManageArea = new PerstateManageArea();
				if(StringUtils.isNotEmpty(where.trim()))
				{
					perstateManageArea = (PerstateManageArea)JsonMapper.fromJsonString(where.trim(),PerstateManageArea.class);
				}
				
				Page<PerstateManageArea> page = new Page<PerstateManageArea>();
				page.setPageSize(pageSize);
				page.setPageNo(pageIndex);
				page.setOrderBy(orderby);
				perstateManageArea.setPage(page);
				ReturnResult returnResult = new ReturnResult();
				returnResult.setList(perstateManageAreaService.getPerstateManageAreaGroupList(perstateManageArea));
				Map<String,Object> dataPagination = new HashMap<String, Object>();
				dataPagination.put("totalRow", perstateManageArea.getPage().getCount());
				dataPagination.put("pageSize", perstateManageArea.getPage().getPageSize());
				dataPagination.put("pageIndex", perstateManageArea.getPage().getPageNo());
				
				returnResult.setPage(dataPagination);
				body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
				body.setResultMsg(AuthEnum.success.toString());
				body.setReturnResult(returnResult);
			}
			else
			{
				body.setResultCode(String.valueOf(AuthEnum.failloginexception.ordinal()));
				body.setResultMsg(AuthEnum.failloginexception.toString());
			}
		}
		catch(Exception e)
		{
			logger.debug(e.getMessage());
			body.setResultCode(String.valueOf(AuthEnum.faildateerror.ordinal()));
			body.setResultMsg(AuthEnum.faildateerror.toString());
		}
		return body;
	}
	
	
	/**
	 *社区业态综合数据-分公司业态收费面积
	 * 
	 * @param sso 
	 * 			验证信息
	 * @param pageSize
	 *            每页显示条数
	 * @param pageIndex
	 *            第几页
	 * @param where
	 *        查询条件
	 *  @param orderby
	 *        排序字段
	 * @return 集团业态收费面积查询列表（json）
	 * @author lgx Date:2016年5月5日；
	 */
	@POST
	@Path("/getPerstateManageAreaCompanyList")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<ReturnResult> getPerstateManageAreaCompanyList(@FormParam("sso") String sso,@FormParam("pageSize") int pageSize,@FormParam("pageIndex") int pageIndex,
			@FormParam("where") String where,@FormParam("orderby") String orderby) 
	{
		ResponseBody<ReturnResult> body = new ResponseBody<ReturnResult>();
		try
		{
			Map<String, Object> mapJsonSso  = (Map<String, Object>)JsonMapper.fromJsonString(sso,Map.class);
			if(mapJsonSso.get("token")!=null)
			{
				PerstateManageArea perstateManageArea = new PerstateManageArea();
				if(StringUtils.isNotEmpty(where.trim()))
				{
					perstateManageArea = (PerstateManageArea)JsonMapper.fromJsonString(where.trim(),PerstateManageArea.class);
				}
				
				Page<PerstateManageArea> page = new Page<PerstateManageArea>();
				page.setPageSize(pageSize);
				page.setPageNo(pageIndex);
				page.setOrderBy(orderby);
				perstateManageArea.setPage(page);
				ReturnResult returnResult = new ReturnResult();
				returnResult.setList(perstateManageAreaService.getPerstateManageAreaCompanyList(perstateManageArea));
				Map<String,Object> dataPagination = new HashMap<String, Object>();
				dataPagination.put("totalRow", perstateManageArea.getPage().getCount());
				dataPagination.put("pageSize", perstateManageArea.getPage().getPageSize());
				dataPagination.put("pageIndex", perstateManageArea.getPage().getPageNo());
				
				returnResult.setPage(dataPagination);
				body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
				body.setResultMsg(AuthEnum.success.toString());
				body.setReturnResult(returnResult);
			}
			else
			{
				body.setResultCode(String.valueOf(AuthEnum.failloginexception.ordinal()));
				body.setResultMsg(AuthEnum.failloginexception.toString());
			}
		}
		catch(Exception e)
		{
			logger.debug(e.getMessage());
			body.setResultCode(String.valueOf(AuthEnum.faildateerror.ordinal()));
			body.setResultMsg(AuthEnum.faildateerror.toString());
		}
		return body;
	}
	
	
	
	/**
	 *社区业态综合数据-分公司项目收费面积
	 * 
	 * @param sso 
	 * 			验证信息
	 * @param pageSize
	 *            每页显示条数
	 * @param pageIndex
	 *            第几页
	 * @param where
	 *        查询条件
	 *  @param orderby
	 *        排序字段
	 * @return 集团业态收费面积查询列表（json）
	 * @author lgx Date:2016年5月5日；
	 */
	@POST
	@Path("/getPerstateManageAreaProjectList")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<ReturnResult> getPerstateManageAreaProjectList(@FormParam("sso") String sso,@FormParam("pageSize") int pageSize,@FormParam("pageIndex") int pageIndex,
			@FormParam("where") String where,@FormParam("orderby") String orderby) 
	{
		ResponseBody<ReturnResult> body = new ResponseBody<ReturnResult>();
		try
		{
			Map<String, Object> mapJsonSso  = (Map<String, Object>)JsonMapper.fromJsonString(sso,Map.class);
			if(mapJsonSso.get("token")!=null)
			{
				PerstateManageArea perstateManageArea = new PerstateManageArea();
				if(StringUtils.isNotEmpty(where.trim()))
				{
					perstateManageArea = (PerstateManageArea)JsonMapper.fromJsonString(where.trim(),PerstateManageArea.class);
				}
				
				Page<PerstateManageArea> page = new Page<PerstateManageArea>();
				page.setPageSize(pageSize);
				page.setPageNo(pageIndex);
				page.setOrderBy(orderby);
				perstateManageArea.setPage(page);
				ReturnResult returnResult = new ReturnResult();
				returnResult.setList(perstateManageAreaService.getPerstateManageAreaCompanyList(perstateManageArea));
				Map<String,Object> dataPagination = new HashMap<String, Object>();
				dataPagination.put("totalRow", perstateManageArea.getPage().getCount());
				dataPagination.put("pageSize", perstateManageArea.getPage().getPageSize());
				dataPagination.put("pageIndex", perstateManageArea.getPage().getPageNo());
				
				returnResult.setPage(dataPagination);
				body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
				body.setResultMsg(AuthEnum.success.toString());
				body.setReturnResult(returnResult);
			}
			else
			{
				body.setResultCode(String.valueOf(AuthEnum.failloginexception.ordinal()));
				body.setResultMsg(AuthEnum.failloginexception.toString());
			}
		}
		catch(Exception e)
		{
			logger.debug(e.getMessage());
			body.setResultCode(String.valueOf(AuthEnum.faildateerror.ordinal()));
			body.setResultMsg(AuthEnum.faildateerror.toString());
		}
		return body;
	}
	
	/**
	 * 社区业态综合数据-收费面积
	 * @param userId
	 * @param password
	 * @param requstSource
	 * @param requstTime
	 * @param signCode
	 * @param indexCode
	 * @return
	 */
	@POST
	@Path("/getPerstateManageArea")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<Object> getPerstateManageArea(@FormParam("userId") String userId,@FormParam("password") String password
			,@FormParam("requstSource") String requstSource,@FormParam("requstTime") String requstTime
			,@FormParam("signCode") String signCode,@FormParam("indexCode") String indexCode)
	{
		ResponseBody<Object> body = new ResponseBody<Object>();
		try
		{
			Map<String,String> object = new HashMap<String, String>();
			object.put("operstateId", indexCode);
			object.put("operstateName", "SQ_INDEX_001_01_04");
			Object result = dataService.getPerstateManageArea(object);
			body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
			body.setResultMsg(AuthEnum.success.toString());
			body.setReturnResult(result);
		}
		catch(Exception e)
		{
			body.setResultCode(String.valueOf(AuthEnum.failothererror.ordinal()));
			body.setResultMsg(AuthEnum.failothererror.toString());
			e.printStackTrace();
		}
		return body;
	}
	
	
	/**
	 * 社区业态综合数据-管理户数
	 * @param userId
	 * @param password
	 * @param requstSource
	 * @param requstTime
	 * @param signCode
	 * @param indexCode
	 * @return
	 */
	@POST
	@Path("/getPerstateManageCustomer")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<Object> getPerstateManageCustomer(@FormParam("userId") String userId,@FormParam("password") String password
			,@FormParam("requstSource") String requstSource,@FormParam("requstTime") String requstTime
			,@FormParam("signCode") String signCode,@FormParam("indexCode") String indexCode)
	{
		ResponseBody<Object> body = new ResponseBody<Object>();
		try
		{
			Map<String,String> object = new HashMap<String, String>();
			object.put("operstateId", indexCode);
			Object result = dataService.getPerstateManageCustomer(object);
			body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
			body.setResultMsg(AuthEnum.success.toString());
			body.setReturnResult(result);
		}
		catch(Exception e)
		{
			body.setResultCode(String.valueOf(AuthEnum.failothererror.ordinal()));
			body.setResultMsg(AuthEnum.failothererror.toString());
			e.printStackTrace();
		}
		return body;
	}
	
	/**
	 * 社区业态综合数据-已收楼数量
	 * @param userId
	 * @param password
	 * @param requstSource
	 * @param requstTime
	 * @param signCode
	 * @param indexCode
	 * @return
	 */
	@POST
	@Path("/getPerstateManageReceivedObject")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<Object> getPerstateManageReceivedObject(@FormParam("userId") String userId,@FormParam("password") String password
			,@FormParam("requstSource") String requstSource,@FormParam("requstTime") String requstTime
			,@FormParam("signCode") String signCode,@FormParam("indexCode") String indexCode)
	{
		ResponseBody<Object> body = new ResponseBody<Object>();
		try
		{
			Map<String,String> object = new HashMap<String, String>();
			object.put("operstateId", indexCode);
			Object result = dataService.getPerstateManageReceivedObject(object);
			body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
			body.setResultMsg(AuthEnum.success.toString());
			body.setReturnResult(result);
		}
		catch(Exception e)
		{
			body.setResultCode(String.valueOf(AuthEnum.failothererror.ordinal()));
			body.setResultMsg(AuthEnum.failothererror.toString());
			e.printStackTrace();
		}
		return body;
	}
	
	/**
	 * 社区业态综合数据-未收楼数量
	 * @param userId
	 * @param password
	 * @param requstSource
	 * @param requstTime
	 * @param signCode
	 * @param indexCode
	 * @return
	 */
	@POST
	@Path("/getPerstateManageNoReceivedObject")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<Object> getPerstateManageNoReceivedObject(@FormParam("userId") String userId,@FormParam("password") String password
			,@FormParam("requstSource") String requstSource,@FormParam("requstTime") String requstTime
			,@FormParam("signCode") String signCode,@FormParam("indexCode") String indexCode)
	{
		ResponseBody<Object> body = new ResponseBody<Object>();
		try
		{
			Map<String,String> object = new HashMap<String, String>();
			object.put("operstateId", indexCode);
			Object result = dataService.getPerstateManageNoReceivedObject(object);
			body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
			body.setResultMsg(AuthEnum.success.toString());
			body.setReturnResult(result);
		}
		catch(Exception e)
		{
			body.setResultCode(String.valueOf(AuthEnum.failothererror.ordinal()));
			body.setResultMsg(AuthEnum.failothererror.toString());
			e.printStackTrace();
		}
		return body;
	}
	
	/**
	 * 应收费总额-管理费-已收楼应收
	 * @param userId
	 * @param password
	 * @param requstSource
	 * @param requstTime
	 * @param signCode
	 * @param indexCode
	 * @return
	 */
	@POST
	@Path("/getPerstateManageReceivedRecMoney")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<Object> getPerstateManageReceivedRecMoney(@FormParam("userId") String userId,@FormParam("password") String password
			,@FormParam("requstSource") String requstSource,@FormParam("requstTime") String requstTime
			,@FormParam("signCode") String signCode,@FormParam("indexCode") String indexCode)
	{
		ResponseBody<Object> body = new ResponseBody<Object>();
		try
		{
			Map<String,String> object = new HashMap<String, String>();
			object.put("operstateId", indexCode);
			Object result = dataService.getPerstateManageReceivedRecMoney(object);
			body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
			body.setResultMsg(AuthEnum.success.toString());
			body.setReturnResult(result);
		}
		catch(Exception e)
		{
			body.setResultCode(String.valueOf(AuthEnum.failothererror.ordinal()));
			body.setResultMsg(AuthEnum.failothererror.toString());
			e.printStackTrace();
		}
		return body;
	}
	
	/**
	 *  应收费总额-管理费-未收楼应收
	 * @param userId
	 * @param password
	 * @param requstSource
	 * @param requstTime
	 * @param signCode
	 * @param indexCode
	 * @return
	 */
	@POST
	@Path("/getPerstateManageNoReceivedRecMoney")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<Object> getPerstateManageNoReceivedRecMoney(@FormParam("userId") String userId,@FormParam("password") String password
			,@FormParam("requstSource") String requstSource,@FormParam("requstTime") String requstTime
			,@FormParam("signCode") String signCode,@FormParam("indexCode") String indexCode)
	{
		ResponseBody<Object> body = new ResponseBody<Object>();
		try
		{
			Map<String,String> object = new HashMap<String, String>();
			object.put("operstateId", indexCode);
			Object result = dataService.getPerstateManageNoReceivedRecMoney(object);
			body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
			body.setResultMsg(AuthEnum.success.toString());
			body.setReturnResult(result);
		}
		catch(Exception e)
		{
			body.setResultCode(String.valueOf(AuthEnum.failothererror.ordinal()));
			body.setResultMsg(AuthEnum.failothererror.toString());
			e.printStackTrace();
		}
		return body;
	}
	
	
	/**
	 * 已收费总额-管理费-实收金额
	 * @param userId
	 * @param password
	 * @param requstSource
	 * @param requstTime
	 * @param signCode
	 * @param indexCode
	 * @return
	 */
	@POST
	@Path("/getPerstateManageDealRecMoney")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<Object> getPerstateManageDealRecMoney(@FormParam("userId") String userId,@FormParam("password") String password
			,@FormParam("requstSource") String requstSource,@FormParam("requstTime") String requstTime
			,@FormParam("signCode") String signCode,@FormParam("indexCode") String indexCode)
	{
		ResponseBody<Object> body = new ResponseBody<Object>();
		try
		{
			Map<String,String> object = new HashMap<String, String>();
			object.put("operstateId", indexCode);
			Object result = dataService.getPerstateManageDealRecMoney(object);
			body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
			body.setResultMsg(AuthEnum.success.toString());
			body.setReturnResult(result);
		}
		catch(Exception e)
		{
			body.setResultCode(String.valueOf(AuthEnum.failothererror.ordinal()));
			body.setResultMsg(AuthEnum.failothererror.toString());
			e.printStackTrace();
		}
		return body;
	}
	
	/**
	 * 已收费总额-管理费-减免金额
	 * @param userId
	 * @param password
	 * @param requstSource
	 * @param requstTime
	 * @param signCode
	 * @param indexCode
	 * @return
	 */
	@POST
	@Path("/getPerstateManageDealRateRecMoney")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<Object> getPerstateManageDealRateRecMoney(@FormParam("userId") String userId,@FormParam("password") String password
			,@FormParam("requstSource") String requstSource,@FormParam("requstTime") String requstTime
			,@FormParam("signCode") String signCode,@FormParam("indexCode") String indexCode)
	{
		ResponseBody<Object> body = new ResponseBody<Object>();
		try
		{
			Map<String,String> object = new HashMap<String, String>();
			object.put("operstateId", indexCode);
			Object result = dataService.getPerstateManageDealRateRecMoney(object);
			body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
			body.setResultMsg(AuthEnum.success.toString());
			body.setReturnResult(result);
		}
		catch(Exception e)
		{
			body.setResultCode(String.valueOf(AuthEnum.failothererror.ordinal()));
			body.setResultMsg(AuthEnum.failothererror.toString());
			e.printStackTrace();
		}
		return body;
	}
	
	/**
	 *  欠费总额-管理费-已收楼欠费
	 * @param userId
	 * @param password
	 * @param requstSource
	 * @param requstTime
	 * @param signCode
	 * @param indexCode
	 * @return
	 */
	@POST
	@Path("/getPerstateManageChargeArrearMoney")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<Object> getPerstateManageChargeArrearMoney(@FormParam("userId") String userId,@FormParam("password") String password
			,@FormParam("requstSource") String requstSource,@FormParam("requstTime") String requstTime
			,@FormParam("signCode") String signCode,@FormParam("indexCode") String indexCode)
	{
		ResponseBody<Object> body = new ResponseBody<Object>();
		try
		{
			Map<String,String> object = new HashMap<String, String>();
			object.put("operstateId", indexCode);
			Object result = dataService.getPerstateManageChargeArrearMoney(object);
			body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
			body.setResultMsg(AuthEnum.success.toString());
			body.setReturnResult(result);
		}
		catch(Exception e)
		{
			body.setResultCode(String.valueOf(AuthEnum.failothererror.ordinal()));
			body.setResultMsg(AuthEnum.failothererror.toString());
			e.printStackTrace();
		}
		return body;
	}
	
	
	/**
	 * 欠费总额-管理费-未收楼欠费
	 * @param userId
	 * @param password
	 * @param requstSource
	 * @param requstTime
	 * @param signCode
	 * @param indexCode
	 * @return
	 */
	@POST
	@Path("/getPerstateManageNoChargeArrearMoney")
	@Produces(MediaType.APPLICATION_JSON)
	@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
	public ResponseBody<Object> getPerstateManageNoChargeArrearMoney(@FormParam("userId") String userId,@FormParam("password") String password
			,@FormParam("requstSource") String requstSource,@FormParam("requstTime") String requstTime
			,@FormParam("signCode") String signCode,@FormParam("indexCode") String indexCode)
	{
		ResponseBody<Object> body = new ResponseBody<Object>();
		try
		{
			Map<String,String> object = new HashMap<String, String>();
			object.put("operstateId", indexCode);
			Object result = dataService.getPerstateManageNoChargeArrearMoney(object);
			body.setResultCode(String.valueOf(AuthEnum.success.ordinal()));
			body.setResultMsg(AuthEnum.success.toString());
			body.setReturnResult(result);
		}
		catch(Exception e)
		{
			body.setResultCode(String.valueOf(AuthEnum.failothererror.ordinal()));
			body.setResultMsg(AuthEnum.failothererror.toString());
			e.printStackTrace();
		}
		return body;
	}
	
	
}
